package com.example.demo111111.service.impl;


import com.example.demo111111.Result.PageResult;
import com.example.demo111111.dao.AuditMerchantDao;
import com.example.demo111111.dao.MerchantDao;
import com.example.demo111111.dao.ProductDao;
import com.example.demo111111.entity.AuditMerchant;
import com.example.demo111111.entity.Merchant;
import com.example.demo111111.service.AuditMerchantService;
import com.example.demo111111.service.MerchantService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;


@Service
public class AuditMerchantServiceImpl implements AuditMerchantService {


    @Resource
    private AuditMerchantDao auditMerchantDao;

    @Override
    public Boolean save(AuditMerchant auditMerchant) {
        if (auditMerchant.getStatus()==null){
            auditMerchant.setStatus(1);
        }
        auditMerchant.setCreate_time(LocalDateTime.now());
        auditMerchant.setUpdate_time(LocalDateTime.now());
         Boolean result=auditMerchantDao.save(auditMerchant);
        return result;
    }

    @Override
    public Boolean update(AuditMerchant auditMerchant) {
        auditMerchant.setUpdate_time(LocalDateTime.now());
        Boolean result=auditMerchantDao.update(auditMerchant);
        return result;
    }


    public PageResult pageQuery(AuditMerchant auditMerchant) {
        PageHelper.startPage(auditMerchant.getPage(),auditMerchant.getPageSize());
        Page<AuditMerchant> page=auditMerchantDao.pageQuery(auditMerchant);
        long total=page.getTotal();
        List<AuditMerchant> records=page.getResult();
        return new PageResult(total,records);
    }

    @Override
    public Boolean deltete(List<Long> ids) {

        Boolean result = null;
        for (Long id : ids) {
            result = auditMerchantDao.deleteById(id);
        }
        return result;
    }
}
